package com.encryption.util;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import com.encryption.service.ca.util.StringUtil;

/**
 * 
 * @author user
 * @version $Id: AuthUtil.java,v 0.1 2012-12-23 下午01:58:41 user Exp $
 */
public class AuthUtil {
    
    private static String mac = "78-e4-00-df-1f-3e";

    public static Boolean isPass() {
        if (StringUtil.equalsIgnoreCase(mac, getMacOnWindow())) {
            return true;
        }
        return false;
    }
    
    public static String getMacOnWindow() {
        try {
            String mac = null;
            Process process = Runtime.getRuntime().exec("ipconfig /all");
            BufferedReader buffer = new BufferedReader(new InputStreamReader(process
                .getInputStream()));
            for (String line = buffer.readLine(); line != null; line = buffer.readLine()) {
                int index = line.indexOf("Physical Address");
                if (index <= 0) {
                    index = line.indexOf("物理地址. . . . . . . . . . . . . :");
                    if (index <= 0)
                        continue;
                    mac = line.substring(index + "物理地址. . . . . . . . . . . . . :".length());
                    break;
                }
                mac = line.substring(index + 36);
                break;
            }
            buffer.close();
            process.waitFor();
           return StringUtil.replace(mac, "-", "");
           
        } catch (Exception exception) {
            exception.printStackTrace();
            return null;
        }
    }
}
